package chapter08_oop._singleton;

/**
 * ClassName: BankTest
 * Package: capter08._singleton
 * Description:
 *
 * 单例(Singleton)设计模式--饿汉式
 *
 * @Author SherryAn
 * @Create 2025/7/20 20:13
 */
public class BankTest {
    public static void main(String[] args) {
//        Bank bank1=new Bank();
//        Bank bank2=new Bank();

        Bank bank1=Bank.getInstance();
        Bank bank2=Bank.getInstance();

        System.out.println(bank1==bank2);//true

    }
}

class Bank{
//    1.类的构造器私有化
    private Bank(){

    }
//    2.在类的内部创建当前类的实例
    private static Bank instance=new Bank();
//    3.使用get方法获取当前类的实例，必须声明为static

    public static Bank getInstance() {
        return instance;
    }


}
